package com.yyk.yykywd.mvvm.model

import com.yyk.yykywd.*
import com.yyk.yykywd.base.BaseResponse
import com.yyk.yykywd.http.ApiService
import com.yyk.yykywd.mvvm.entity.SearchBean
import com.yyk.yykywd.mvvm.entity.WorkNumBean
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * 文件描述：
 * Created by guo on 2019-12-06.
 */
class SearchModel {
    fun search(type: String, name: String,page:String,num:String, getSearch: GetSearch) {
        val newMap = getNewMap()
        putUid(newMap)
        putName(newMap,name)
        if (type == AGENT) {
            putType(newMap,"2")
        } else {
            putType(newMap,"1")
        }
        putPage(newMap,page)
        putNum(newMap,num)
        putSign(newMap)
        ApiService.getInstance().api.postSearch(newMap)
                .subscribeOn(Schedulers.io()) //调度线程
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io()) //取消订阅
                .subscribe(object : Observer<SearchBean> {
                    override fun onComplete() {
                    }

                    override fun onSubscribe(d: Disposable?) {
                    }

                    override fun onNext(t: SearchBean) {
                        getSearch.getInfo(t)
                    }

                    override fun onError(e: Throwable) {
                        getSearch.onError(e.toString())
                    }

                })
    }

    interface GetSearch : BaseResponse {
        fun getInfo(info: SearchBean)
    }
}